var _loginUser=JSON.parse(localStorage.getItem("loginUser"));
var _loginAccount= _loginUser.userNo;
var _timeStamp=_loginUser.timeStamp;
var _appId = localStorage.getItem('reqConfItem').split(',')[0];
var token = { appId: _appId, device_name: 'testPad', loginUserCode: _loginAccount, timeStamp: _timeStamp, language: language, loginSysCode: 'ICM' }
console.log('token='+JSON.stringify(token));
var encdeToken = b.encode(encodeURI(JSON.stringify(token)));
console.log('encodedToken='+encdeToken);

var param = localStorage.getItem('param');
alert('页面传入参数：'+param);

getChartData();
getGridData();

function createChart(_firstData,_secondData){
    var chartDom = document.getElementById('_chart');
    var myChart = echarts.init(chartDom);
    var option;
    option = {
        tooltip: {
            trigger: 'axis'
        },
        grid: {
            left: '3%',
            right: '3%',
            bottom: '3%',
            containLabel: true
        },
        calculable: true,
        xAxis: [
            {
                axisLabel:{
                    textStyle:{
                        fontSize:'32px',
                        color:'#ffffff'
                    }
                },
                type: 'category',
                data: ['OP1', 'OP2', 'OP3', 'OP4', 'OP5', 'OP6']
            }
        ],
        yAxis: [
            {
                type: 'value',
                axisLabel:{
                    textStyle:{
                        fontSize:'32px',
                        color:'#ffffff'
                    }
                }
            }
        ],
        series: [
            {
                type: 'bar',
                data: [25.6, 76.7, 135.6, 162.2, 32.6, 20.0],
                itemStyle:{
                    color:'#F05B02'
                },
                label: {
                    show: true,
                    position: 'top',
                    textStyle:{
                        fontSize:'32px',
                        color:'#ffffff'
                    }
                }
            }
        ]
    };
    option && myChart.setOption(option);
}

function getChartData(){

    var signData = { 
        startTime:param.startTime,
        endTime:param.endTime,
        stationType:param.stationType,
        line:param.line,
        stage:param.stage,
        appId: token.appId, device_name: token.device_name, loginUserCode: token.loginUserCode, timeStamp: token.timeStamp, language: token.language, loginSysCode: token.loginSysCode };
    var sign = createSign(signData);
    $.ajax({
        url: icmpApi + '/report/getStationOPList',
        data: JSON.stringify({ startTime:param.startTime,endTime:param.endTime,stationType:param.stationType,line:param.line,sign: sign }),
        headers: { token: encdeToken },
        dataType: 'json',
        type: 'post',
        success: function (r) {
            console.log(r);
            if(r.error==0){
                
            }
            else {
                alert(icmpApi + '/report/getStationOPList 调用结果：' + r.msg);
            }
        },
        complete:function(){
            alert('图表以静态数据展示');
            createChart(null,null);
        }
    });
}

function getGridData(){
    var signData = { 
        startTime:param.startTime,
        endTime:param.endTime,
        stationType:param.stationType,
        line:param.line,
        stage:param.stage,
        empno:_loginAccount,
        appId: token.appId, device_name: token.device_name, loginUserCode: token.loginUserCode, timeStamp: token.timeStamp, language: token.language, loginSysCode: token.loginSysCode };
    var sign = createSign(signData);
    $.ajax({
        url: icmpApi + '/report/getAOIDefectByOP',
        data: JSON.stringify({ startTime:param.startTime,endTime:param.endTime,stationType:param.stationType,line:param.line,sign: sign }),
        headers: { token: encdeToken },
        dataType: 'json',
        type: 'post',
        success: function (r) {
            console.log(r);
            if(r.error==0){
                
            }
            else {
                alert(icmpApi + '/report/getAOIDefectByOP 调用结果：' + r.msg);
            }
        },
        complete:function(){
            alert('表格以静态数据展示');
        }
    });
}